<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>数据可视化</title>
</head>
<body>
<script src="https://cdn.bootcss.com/echarts/4.6.0/echarts.min.js"></script>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>

<!-- 为 ECharts 准备一个具备大小（宽高）-->
<div id="main" style="width: 600px;height:500px;"></div>
<div>
    <button id="show">图表展示</button>
</div>

<script type="text/javascript">

    // 基于准备好的dom，初始化echarts实例

    var myChart = echarts.init(document.getElementById('main'));

    $("#show").click(function show() {
        $.ajax({
            type : "get",
            url : "/line",
            contentType: 'application/json',
            success:function(data){
                option = {
                    title: {
                        text: '网站每日登录人数'
                    },
                    xAxis: {
                        type: 'category',
                        data: data.calculatedList
                    },
                    yAxis: {
                        type: 'value'
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            mark: {show: true},
                            dataView: {show: true, readOnly: false},
                            restore: {show: true},
                            saveAsImage: {show: true}
                        }
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    series: [{
                        data: data.numDateList,
                        type: 'line',
                        showBackground: true,
                        color: '#18cbdb',
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
            },
            error:function(data){
                console.log("error")
                console.log(data)
            }
        })
    })

</script>

</body>
</html>